<%@ page language="java" contentType="application/json; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.number.dao.StudentDao"%>
<%@ page import="com.number.bean.Page"%>
<%@ page import="com.number.bean.Student"%>
<%
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");

    String stu_id = request.getParameter("stu_id");
    String stu_code = request.getParameter("stu_code");
    String stu_name = request.getParameter("stu_name");
    String stu_sex = request.getParameter("stu_sex");
    String stu_age = request.getParameter("stu_age");
    String stu_political = request.getParameter("stu_political");
    String stu_original = request.getParameter("stu_original");
    String stu_professional = request.getParameter("stu_professional");

    Student student = new Student();
    student.setStu_code(stu_code);
    student.setStu_name(stu_name);
    student.setStu_sex(Integer.parseInt(stu_sex));
    student.setStu_age(Integer.parseInt(stu_age));
    student.setStu_political(stu_political);
    student.setStu_original(stu_original);
    student.setStu_professional(stu_professional);
    
    System.out.println(student.toString());

    StudentDao stuDao = StudentDao.getInstance();
    // 修改
    if (stu_id != null && stu_id.length() > 0) {
        student.setStu_id(Long.parseLong(stu_id));
        stuDao.update(student);
    }
    // 添加
    else {
        stuDao.insert(student);
    }
    out.print("{success:true, msg:'保存成功'}");
%>
